<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="教师名称" prop="teaName">
          <el-input
            v-model="queryParams.teaName"
            placeholder="请输入教师名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="课程名称" prop="curriculum">
          <el-input
            v-model="queryParams.curriculum"
            placeholder="请输入课程名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:class:export']"
          >导出课程表</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="classList" >
        <el-table-column  type="selection" width="55" align="center" />
        <el-table-column label="教师上传课程表" align="center" prop="id" />
        <el-table-column label="教师名称" align="center" prop="teaName" />
        <el-table-column label="课程类型" align="center" prop="teaType" />
        <el-table-column label="课程名称" align="center" prop="curriculum" />
        <el-table-column sortable label="选修人数" align="center" prop="number" />
        <el-table-column sortable label="课程平均评分" align="center" prop="allScore" />
        <el-table-column sortable label="课程总评分" align="center" prop="score" />
        <el-table-column label="课程简介" align="center" prop="introduction" />
        <el-table-column label="课程优势" align="center" prop="advantage" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="CheckClass(scope.row)"
            >选择本门课程</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改【请填写功能名称】对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <!-- <el-form-item label="教师名称" prop="teaName">
            <el-input v-model="form.teaName" placeholder="请输入教师名称" />
          </el-form-item> -->
          <el-form-item label="课程类型" prop="teaType">
            <el-input  :disabled="true" v-model="form.teaType" placeholder="请输入课程名称" />
          </el-form-item>
          <el-form-item label="课程名称" prop="curriculum">
            <el-input  :disabled="true" v-model="form.curriculum" placeholder="请输入课程名称" />
          </el-form-item>
          <el-form-item label="课程教师" prop="teaName">
            <el-input  :disabled="true" v-model="form.teaName" placeholder="请输入课程名称" />
          </el-form-item>
          <el-form-item label="课程简介" prop="introduction">
            <el-input  :disabled="true" v-model="form.introduction" placeholder="请输入课程简介" />
          </el-form-item>
          <el-form-item label="课程优势" prop="advantage">
            <el-input   :disabled="true" v-model="form.advantage" placeholder="请输入您的课程优势" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listClass, Check, getClass,delClass, addClass, updateClass } from "@/api/system/class";
  
  export default {
    name: "Class",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        classList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          teaName: null,
          teaType: null,
          curriculum: null,
          number: null,
          allScore: null,
          score: null,
          introduction: null,
          advantage: null,
  
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listClass(this.queryParams).then(response => {
          this.classList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          teaName: null,
          teaType: null,
          curriculum: null,
          number: null,
          allScore: null,
          score: null,
          introduction: null,
          advantage: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    
    
        /** 选课的方法 */
      CheckClass(row) {
        this.reset();
        const id = row.id || this.ids
        getClass(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "是否选择";
        });
      },


      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              Check(this.form).then(response => {
                this.$modal.msgSuccess("选课成功");
                this.open = false;
                this.getList();
              });
            } e
          }
        }
        );
      },
    
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/class/export', {
          ...this.queryParams
        }, `class_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  